import { View, Text, Image } from '@tarojs/components';
import cartIcon from '@/assets/images/goods/cart-icon.png';
import Coupon from '../Coupon';
import Price from '../Price';
import './index.scss';

export default function ({
  type = 'search',
  goodsInfo,
  onHandle = () => {},
  onAddCart = () => {},
}: any) {
  const _onClick = () => {
    onHandle && onHandle();
  };
  const _onAddCart = (e) => {
    e.stopPropagation();
    // @ts-ignore
    onAddCart(goodsInfo);
  };
  return (
    <View className="goods-content-list" onClick={_onClick}>
      <Image className="goods-image" mode="aspectFit" src={goodsInfo.goods_pic_url} />
      <View className="goods-title">{goodsInfo.goods_name}</View>
      <View className="coupon-content">
        {Array.isArray(goodsInfo.goods_keywords) &&
          goodsInfo.goods_keywords.filter(item => !!item).map((item) => {
            return (
              <Coupon color="" key={item}>
                {item}
              </Coupon>
            );
          })}
        {/* <View className="use">先用后付</View> */}
      </View>
      <View className="goods-bottom">
        {/* <Price color="#333333" price={goodsInfo.vip_price} /> */}
        {/* <Text className="sales">已售{goodsInfo.sales}</Text> */}
        <Price color="#333333" price={goodsInfo.vip_price || goodsInfo.goods_min_price} />
        {type === 'search' ? (
          <Text className="sales">
            已售
            {goodsInfo.goods_sales === undefined
              ? goodsInfo.cartoon_goods_sales
              : goodsInfo.goods_sales}
          </Text>
        ) : (
          <Image src={cartIcon} className="cart-icon" onClick={_onAddCart} />
        )}
      </View>
    </View>
  );
}
